package com.huawei.appgallery.foundation.ui.framework.widget;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import o.azb;
import o.dky.h;
import o.dky.i;
import o.dky.j;
import o.Logger;
import o.ContentManager;
import o.eth;
import o.evk;
import o.ll;

public class NetworkRemindBar extends LinearLayout implements OnClickListener {
    private int ʻ = 0;
    private c ʼ;
    private final BroadcastReceiver ʽ = new 5(this);
    private final Context ˊ;
    private View ˋ;
    private View ˋॱ;
    private boolean ˎ = false;
    private TextView ˏ;
    private View ॱ;
    private int ॱॱ;
    private View ᐝ;

    public interface c {
        void ʳ();

        void ﹶ();

        void ﾟॱ();
    }

    public NetworkRemindBar(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ˊ = context;
        ॱॱ();
    }

    public NetworkRemindBar(Context context) {
        super(context);
        this.ˊ = context;
        ॱॱ();
    }

    private static final String ʽ() {
        return ContentManager.getInstant().getContext().getPackageName() + ".broadcast.NetworkRemindBar.RemindBarHiden";
    }

    public void setNetworkRemindBarListener(c cVar) {
        this.ʼ = cVar;
    }

    private void ॱॱ() {
        this.ॱ = LayoutInflater.from(this.ˊ).inflate(i.ˍ, this);
        azb.ˎ(this.ॱ, h.ˎͺ);
        this.ˋ = this.ॱ.findViewById(h.ˑॱ);
        this.ᐝ = this.ॱ.findViewById(h.ՙ);
        azb.ˋ(this.ᐝ);
        this.ˋॱ = this.ॱ.findViewById(h.ٴ);
        this.ˏ = (TextView) this.ॱ.findViewById(h.ॱꜟ);
        this.ˋ.setOnClickListener(this);
        this.ᐝ.setOnClickListener(this);
        this.ˋॱ.setOnClickListener(this);
    }

    private void ˏ(int i) {
        Logger.ˋ("NetworkRemindBar", "showWarning() warningType: " + i);
        this.ʻ = i;
        this.ॱ.setVisibility(0);
        new Handler().postDelayed(new Runnable(this) {
            final /* synthetic */ NetworkRemindBar ˋ;

            {
                this.ˋ = r1;
            }

            public void run() {
                if (this.ˋ.ʻ == 0) {
                    this.ˋ.ˏ.setText(j.ॱͺ);
                } else if (this.ˋ.ʻ == 1) {
                    this.ˋ.ˏ.setText(j.ॱॱ);
                }
            }
        }, 200);
        ˊ();
    }

    public void ˊ() {
        if (this.ʼ != null && this.ॱॱ > 0) {
            this.ʼ.ﹶ();
        }
    }

    public void ˋ() {
        if (getVisibility() != 8) {
            setVisibility(8);
            if (this.ʼ != null) {
                this.ʼ.ʳ();
            }
        }
    }

    public void onClick(View view) {
        Logger.ˎ("NetworkRemindBar", "onClick netremind view again to refresh main page , When the interface shows no network ");
        if (view == this.ˋॱ || view == this.ᐝ) {
            eth.ˊ(this.ˊ);
        } else if (view == this.ˋ) {
            ʼ();
        }
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ll.ˏ(getContext()).ˏ(this.ʽ, new IntentFilter(ʽ()));
        getContext().registerReceiver(this.ʽ, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        ll.ˏ(getContext()).ˋ(this.ʽ);
        getContext().unregisterReceiver(this.ʽ);
    }

    public void setReconnectStr() {
        this.ˏ.setText(j.ˉॱ);
    }

    public void setNetworkOK() {
        if (ˎ()) {
            new Handler().postDelayed(new Runnable(this) {
                final /* synthetic */ NetworkRemindBar ˋ;

                {
                    this.ˋ = r1;
                }

                public void run() {
                    this.ˋ.ˎ = false;
                    ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent(NetworkRemindBar.ʽ()));
                }
            }, 200);
        }
    }

    public void ॱ(int i) {
        this.ˎ = false;
        Logger.ˋ("NetworkRemindBar", "showLoadingFailed() netErrorCode : " + i);
        if (3 == i) {
            ˏ(0);
        } else {
            ˏ(1);
        }
    }

    public void ॱ() {
        this.ˎ = false;
        evk.ˋ(this.ˊ, this.ˊ.getString(j.ॱʼ), 0).ˋ();
    }

    public void ˏ() {
        this.ˎ = false;
        evk.ˋ(this.ˊ, this.ˊ.getString(j.ॱॱ), 0).ˋ();
    }

    public void setLoadData() {
        if (getVisibility() == 0) {
            ʼ();
        }
    }

    private void ʼ() {
        Logger.ˎ("NetworkRemindBar", "doReconnect() isReconnecting=" + this.ˎ);
        if (this.ʼ != null && !this.ˎ) {
            this.ˎ = true;
            setReconnectStr();
            this.ʼ.ﾟॱ();
        }
    }

    public boolean ˎ() {
        return getVisibility() == 0;
    }

    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        if (getVisibility() == 0) {
            int measuredHeight = getMeasuredHeight();
            if (measuredHeight > 0 && measuredHeight != this.ॱॱ) {
                this.ॱॱ = measuredHeight;
                if (this.ʼ != null) {
                    this.ʼ.ﹶ();
                }
            }
        }
    }
}
